<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.scalar.chiptrack.operations.material.MaterialRequestLineItem" %>
<%@ page import="com.scalar.chiptrack.operations.material.forms.MaterialRequestForm" %> 
<%@ page import="com.scalar.chiptrack.utils.ConfigManager,com.scalar.chiptrack.operations.material.MaterialRequest"%>
<%@ page import="com.scalar.chiptrack.users.User" %>
<%@ page import="com.scalar.chiptrack.users.Functionality" %>
<%@ page import="com.scalar.chiptrack.utils.StringUtils" %>

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/materialRequest.do"/>

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<html:html>

<HEAD>
<TITLE>Scalar Soft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type="text/css" rel="stylesheet">
</HEAD>
<style type="text/css">
a { text-decoration : none} 
</style>
<body>
<%
    // code the get the Material Request Line Items Linked List
      java.util.LinkedList lineItemlist = null;
      try{
         lineItemlist = (java.util.LinkedList)request.getAttribute("lineItemList");
         if(lineItemlist==null) lineItemlist = new java.util.LinkedList();
       }catch(Exception ex){ }
     
     // code to get Material Request form element from the request
     
     MaterialRequestForm materialRequestForm = null;
     try{
        materialRequestForm = (MaterialRequestForm)request.getAttribute("materialRequestForm");
        
     }catch(Exception ex){ }
     
     java.util.ArrayList optionlist = null;
     org.apache.struts.util.LabelValueBean option = null;

     try{
         optionlist = (java.util.ArrayList)request.getAttribute("partNumberList");
         if(optionlist==null) optionlist = new java.util.ArrayList();
        }catch(Exception e){  }
      int optionlistsize = optionlist.size();
%>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" >
  <tr>
    <td width="10%">&nbsp;
    </td>
    <td width="80%">
    <p align="center"><font face="Verdana"><b>Materials Transfer Request and Authorization</b></font></td>
    <td width="10%">
    <table align=center background='<%=chipTracContext%>/jsp/includes/images/printer_icon_small.gif'><tr><td>
                <chiptrack:restrictedLink functionality="<%=Functionality.MATERIAL_REQUEST%>" action="<%=User.USER_ACTION_VIEW%>" href="javascript:window.print();" >
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</chiptrack:restrictedLink>
                </td></tr>
            </table>
    </td>
  </tr>
</table>
<br>
<table border="2" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1">
  <tr>
    <td width="49%" colspan="2" bgcolor="#C0C0C0">
    <font size="2" face="Verdana"><b>INTERNAL USE :</b>&nbsp; 
    Issuing Department&nbsp;&nbsp;&nbsp; (From)</font></td>
    <td width="51%" bgcolor="#C0C0C0" colspan="2">
    <font size="2" face="Verdana"><b>INTERNAL USE</b> 
    (To) Receiving Department : <b>Eng./FAE Name</b></font></td>
  </tr>
  <tr>
    <td width="49%" colspan="2">
    <font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getInternalIssueDepartment()%></font>
    </td>
    <td width="51%" colspan="2">
    <font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getInternalReceivingDepartment()%></font>
    </td>
  </tr>
  <tr>
    <td width="49%" colspan="2" bgcolor="#C0C0C0">
    <font size="2" face="Verdana"><b>EXTERNAL USE :</b> 
    Issuing Department&nbsp;&nbsp; (From)</font></td>
    <td width="51%" bgcolor="#C0C0C0" colspan="2">
    <font size="2" face="Verdana"><b>EXTERNAL USE</b> 
    (To) Receiving Department : <b>Customer/Partner Name</b></font></td>
  </tr>
  <tr>
    <td width="49%" colspan="2">
    <font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getExternalIssueDepartment()%></font>
    </td>
    <td width="51%" colspan="2">
    <font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getExternalReceivingDepartment()%></font>
    </td>
  <tr>
    <td width="49%" colspan="2">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%"  height="19">
      <tr>
        <td width="25%" bgcolor="#C0C0C0" height="19">
        <font size="2" face="Verdana"><b>Cost Center # :</b></font></td>
        <td width="75%" height="19"><font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getCostCenter()%></font></td>
      </tr>
    </table>
    </td>
    <td width="51%" colspan="2">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" >
      <tr>
        <td width="25%" bgcolor="#C0C0C0"><B>&nbsp;</B></td>
        <td width="75%">&nbsp;</td>
      </tr>
    </table>
    </td>
  </tr>
  <tr>
    <td width="25%">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber5">
      <tr>
        <td width="50%" bgcolor="#C0C0C0"><font size="2" face="Verdana"><B>
        Authorized by :<B></font></td>
        <td width="50%"><font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getAuthorizedBy()%></font></td>
      </tr>
    </table>
    </td>
    <td width="24%">
    <p style="margin-left: 10"><font size="2" face="Verdana"><b>Date :</b>&nbsp;<%=materialRequestForm.getAuthorizedDate()%></font></td>
    <td width="26%">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" >
      <tr>
        <td width="25%" bgcolor="#C0C0C0"><font size="2" face="Verdana">
        <b>Requested By :</b> </font></td>
        <td width="25%"><font size="2" face="Verdana">&nbsp;<%=materialRequestForm.getRequestedBy()%></font></td>
      </tr>
    </table>
    </td>
    <td width="25%">&nbsp;</td>
  </tr>
  <tr>
    <td width="49%" colspan="2"><font size="2" face="Verdana"><b>DATE NEEDED BY :</b>&nbsp; <%=materialRequestForm.getDateNeededBy()%></font></td>
    <td width="26%"><font size="2" face="Verdana"><b>Authorized By :</b>&nbsp;<%=materialRequestForm.getRequestAuthorizedBy()%> </font></td>
    <td width="25%"><font face="Verdana" size="2"><b>Date :</b>&nbsp;<%=materialRequestForm.getRequestAuthorizedByDate()%></font></td>
  </tr>
  <tr>
    <td width="49%" colspan="2" valign='top'>
    <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" >
      <tr>
        <td width="14%" bgcolor="#C0C0C0" align="center"><b>
        <font size="2" face="Verdana">ITEM :</font></b></td>
        <td width="18%" bgcolor="#C0C0C0" align="center"><b>
        <font size="2" face="Verdana">QTY REQ : </font></b></td>
        <td width="18%" bgcolor="#C0C0C0" align="center"><b>
        <font size="2" face="Verdana">QTY REC : </font></b></td>
        <td width="50%" bgcolor="#C0C0C0" align="center">
        <p align="left"><b><font size="2" face="Verdana">&nbsp; PART NUMBER</font></b></td>
      </tr>
       <% 
             int count = 0;
             java.util.ListIterator lineItemIterator = lineItemlist.listIterator(0);
             MaterialRequestLineItem materialRequestLineItem = null;
             while(lineItemIterator.hasNext()){ 
                 materialRequestLineItem = (MaterialRequestLineItem)lineItemIterator.next();
                 if(materialRequestLineItem==null)continue;
       %>
      <tr>
        <td width="14%" align='left'><font size="2" face="Verdana">&nbsp;<%=(count+1)%></font></td>
        <td width="18%" align='right'><font size="2" face="Verdana"><%=StringUtils.formatUnits(materialRequestLineItem.getRequestQuantity())%>&nbsp;</font></td>
        <td width="18%" align='right'><font size="2" face="Verdana"><%=StringUtils.formatUnits(materialRequestLineItem.getReceivedQuantity())%>&nbsp;</font></td>
        <td width="50%" align='left' ><font size="2" face="Verdana">&nbsp;<%
             for(int listcount=0;listcount<optionlistsize;listcount++){
                try{

                    option = (org.apache.struts.util.LabelValueBean)optionlist.get(listcount);
                    if(((String)option.getValue()).equals(materialRequestLineItem.getPartNumber()) ){
                        out.println((String)option.getLabel() );
                        break;
                    }
                   }catch(Exception e){
                // nothing just ignore the part number --- verify
                }   
            }
            %></font></td>
      </tr>

      <% count++;
        }
        %>
      
    </table>
    </td>
    <td width="51%" valign="top" colspan="2" valign='top'>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" halign="bottom">
      <tr>
        <td width="100%" bgcolor="#C0C0C0"><b><font size="2" face="Verdana">&nbsp;&nbsp; 
            DESCRIPTION</font></b></td>
         
      </tr>
          
      <tr>

        <td valign='top' valign='top' >
            <hr size="1" color="black"></hr>
           <font face="Verdana" size="2">&nbsp;<%=materialRequestForm.getDescription()%></font>
        </td>
      <tR>
    </table>
       
    </td>
  </tr>
</table>

</body>
</html:html>